<template>
<div>
    <van-nav-bar
      title='收藏夹'
      left-text="返回主页"
      left-arrow
      @click-left="onClickLeft()"
    />
    <div v-if="getbook!=null">
   <van-card v-for="(s,index) in getbook" 
  :key="index"
  :title="getbook[index].name"
  :desc="getbook[index].author"
  :price="getbook[index].price"
  :thumb="'/'+getbook[index].img"
  @click="change1(getbook[index].id,index)"
> 


<template #tags>
    <van-tag plain type="danger">{{getbook[index].category1}}</van-tag>
  </template>
  </van-card>
  </div>
  
  <low-change></low-change>
</div>
</template>
<script>
import  lowchange from '../components/lowchange'
import { Dialog } from 'vant';
import network from '../network';
export default {
    components:{
        "low-change":lowchange,
    },
    data(){
        return{
          getbook:[],
          token:[],
          user_id:[],
        }
    },
     created: function () {
         
         this.user_id=localStorage.getItem("user_id");
         let self=this;
       if(localStorage.getItem("token")==null)
       {
        Dialog.alert({
        title: '请登录',
        message: '登录登录！！',
        theme: 'round-button',
        }).then(() => {
        this.$router.push("/login");
        });
       }
       else if(localStorage.getItem("token")!=null){
           network.getlove_book(this.user_id).then(function(response) {
            self.getbook = response.data;
     })
         
      }
    },
     methods: {
     change1(id,index)
      {
      this.$router.push(`/newpage/${id}/${this.getbook[index].category}`);
     },
    onClickLeft() {
      this.$router.push("/");
    }
    }
}
</script>